#{extends 'main.html' /}
<head>
    <script type="text/javascript">
        function swap(b, p){
            document.getElementById(b).style.display = (document.getElementById(b).style.display == "none") ? "block" : "none";
            document.getElementById(p).src = (document.getElementById(b).style.display == "block") ? "/public/images/minus.gif" : "/public/images/plus.gif";
            
        }
        
        function getRadioCheckedValue(radio_name){
            var oRadio = document.getElementsByName(radio_name);
            for (var i = 0; i < oRadio.length; i++) {
                if (oRadio[i].checked) {
                    return oRadio[i].value;
                }
                
            }
            return '';
        }
        
        function disable(){
            var radioIndex = getRadioCheckedValue('storyId');
            var radioButtons = document.getElementsByName('storyId');
            
            if (radioIndex > 0) {
                document.getElementById('sprintId').disabled = true;
            }
            else {
                if (document.getElementById('sprintId').selectedIndex > 0) {
                    for (var i = 0; i < radioButtons.length; i++) {
                        radioButtons[i].disabled = true;
                    }
                }
                else {
                    for (var i = 0; i < radioButtons.length; i++) {
                        radioButtons[i].disabled = false;
                    }
                    document.getElementById('sprintId').disabled = false;
                    
                }
            }
            
        }
    </script>
</head>
<H2><a style ="color:#400040;" href = "@{Projects.showProject((Long)project.getEntityId())}">${project.name}</a> > <a style ="color:#400040;" href = "@{Tasks.showAllProjectTasks((Long)project.getEntityId())}">Tasks</a> > <a style ="color:#400040;" href = "@{Tasks.showTask(task.getEntityId())}">${task.description}</a> > Edit</H2>
<hr/>
#{form @Tasks.renderEditTask(description,details,priority,typeId,statusId,dependOn,task.getEntityId(),projectId,eventsId,sprintId,userComment), class:'jqtransform', id:'myForm'}
Summary
<sup>
    <FONT COLOR="#ff0000">
        *
    </FONT>
</sup>:
<br/>
<textarea class="validate[required,length[1,100]]" rows="2" cols="40" name = "description" id = "description">${task.description}
</textarea>
<br/>
Description
<sup>
    <FONT COLOR="#ff0000">
        *
    </FONT>
</sup>:
<br/>
<textarea class="validate[required]" name = "description" id = "description" rows="5" cols="40" align="top">${task.details}
</textarea>
<br/>
#{secure.check 'Set/edit priority of a task'}
Priority:
<br/>
<select name = "priority" id="priority">
    #{list items:priorities, as:'priority'}<option selected="selected" value ="${priority}">${priority}<option>
        <script type="text/javascript">
            document.getElementById('priority').value = '${task.priority}';
        </script>
        #{/list}
        </select>
        <br/>
        <br/>
        #{/secure.check}
        Type:
        <br/>
        <select name = "typeId" id = "typeId">
            #{list items:taskTypes, as:'taskType'}<option value ="${taskType.getEntityId()}">${taskType.type}<option>
                <script type="text/javascript">
                    document.getElementById('typeId').value = '${task.type.getEntityId()}';
                </script>
                #{/list}
                </select>
                <br/>
                <br/>
                <br/>
                Status:
                <br/>
                <select name = "statusId" id = "statusId">
                    #{list items:taskStatuses, as:'taskStatus'}<option selected="selected" value ="${taskStatus.getEntityId()}">${taskStatus.status}<option>
                        <script type="text/javascript">
                            document.getElementById('statusId').value = '${task.status.getEntityId()}';
                        </script>
                        #{/list}
                        </select>
                        <br/>
                        <br/>
                        <br/>
                        #{secure.check 'associate a task to a user story'}
                        #{if userStories}
                        <br/>
                        <img src="/public/images/minus.gif" id='y' onclick ="javascript:swap('x','y');"/>Associate to User Story:
                        <div id ='x' style="width:700px;height:210px;overflow-y: scroll;word-wrap:break-word;">
                            <br/>
                            <input name = "storyId" id = "storyId" type = "radio" value ="0L" onchange="javascript:disable();"/>none
                            <br/>
                            <br/>
                            #{list items:userStories, as: 'story'} 
							<input name = "storyId" id = "storyId" type = "radio" value ="${story.getEntityId()}" onchange="javascript:disable();"/><!--	<option value ="${story.getEntityId()}">--> As a/an 
                            #{list items: story.appRoles, as: 'appRole'}
                            ${appRole.name},
                            #{/list}
                            ${story.story}
                            <br/>
                            <br/>
                            #{/list}
                            #{if task.userStory}
                            <script type="text/javascript">
                                var radioButtons = document.getElementsByName('storyId');
                                for (var i = 0; i < radioButtons.length; i++) {
                                    if (radioButtons[i].value == '${task.userStory.getEntityId()}') {
                                    	radioButtons[i].checked = "checked";
										document.getElementById('sprintId').disabled = true;
                                    }
                                }
								
                            </script>
                            #{/if}
							#{else}
							<script type="text/javascript">
							var radioButtons = document.getElementsByName('storyId');
							radioButtons[0].checked = "checked";
							</script>
							#{/else}
                        </div>
                        #{/if}
                        #{/secure.check}
                        <br/>
                        <br/>
                        #{secure.check 'Set/edit dependances between tasks'}
                        #{if dependOn}<img src="/public/images/minus.gif" id='d' onclick ="javascript:swap('b','d');"/>Depends On Task(s):
                        <br/>
                        <br/>
                        #{/if}
                        #{else}
                        #{if availableTasks}<img src="/public/images/minus.gif" id='d' onclick ="javascript:swap('b','d');"/>Depends On Task(s):
                        <br/>
                        <br/>
                        #{/if}
                        #{/else}
                        <div id = 'b' style="width:700px;height:200px;overflow-y: scroll;">
                            #{list items:dependOn, as:'dependOnTask'}<input name = "dependOn" type = "checkbox" value = "${dependOnTask.getEntityId()}" checked = "checked" /><a href="@{Tasks.showTask(dependOnTask.getEntityId())}">${dependOnTask.description}</a>
                            <br/>
                            <br/>
                            #{/list}
                            #{list items:availableTasks, as:'task'}<input name = "dependOn" type = "checkbox" value = "${task.getEntityId()}" /><a href="@{Tasks.showTask(task.getEntityId())}">${task.description}</a>
                            <br/>
                            <br/>
                            #{/list}
                        </div>
                        <br/>
                        <br/>
                        #{/secure.check}
                        #{secure.check 'Associate a task to a specific sprint in my project'}
                        #{if availableSprints}
                        Associate to Sprint:
                        <br/>
                        <select name="sprintId" id = "sprintId" onchange="javascript:disable();">
                            ><option value ="0L">select one ...</option>
                            #{list items:availableSprints, as: 'availableSprint'}<option value ="${availableSprint.getEntityId()}">${availableSprint.name}</option>
                            #{if sprint}
                            <script type="text/javascript">
                                document.getElementById('sprintId').value = '${sprint.getEntityId()}';
                                if (getRadioCheckedValue > 0) {
                                    document.getElementById('sprintId').selectedIndex = 0;
                                    
                                }
                            </script>
                            #{/if}
                            #{/list}
                        </select>
                        <br/>
                        <br/>
                        ` 
                        <br/>
                        #{/if}
                        #{/secure.check}
                        #{secure.check 'associate tasks to event'}
                        #{if availableEvents}<img src="/public/images/minus.gif" id='p' onclick ="javascript:swap('c','p');"/>Associate to Event(s):
                        <br/>
                        #{/if}
                        #{else}
                        #{if associatedEvents}<img src="/public/images/minus.gif" id='p' onclick="javascript:swap('c','p');"/>Associate to Event(s):
                        <br/>
                        <br/>
                        
                        <div id = 'c' style="width:700px;height:200px;overflow-y: scroll;">
                            #{list items:associatedEvents, as: 'associatedEvent'}<input name = "eventsId" id = "eventsId" type = "checkbox" checked="checked" value = "${associatedEvent.getEntityId()}" /><a href="@{Events.showEvent(associatedEvent.getEntityId())}">${associatedEvent.name}</a>
                            <br/>
                            <br/>
                            #{/list}
                            #{list items:availableEvents, as: 'event'}<input name = "eventsId" id = "eventsId" type = "checkbox" value = "${event.getEntityId()}" /><a href="@{Events.showEvent(event.getEntityId())}">${event.name}</a>
                            <br/>
                            <br/>
                            #{/list}
                        </div>
						#{/if}
                        #{/else}
                        <br/>
                        <br/>
                        <br/>
                        #{/secure.check}
                        Comment
                        <sup>
                            <FONT COLOR="#ff0000">
                                *
                            </FONT>
                        </sup>:
                        <br/>
                        <textarea class="validate[required,length[1,1000]]" name = "description" id = "description" rows="10" cols="40" align="top"></textarea>
                        <br/>
                        <br/>
                        <input type="submit" name="submit" class="button" id="submit_btn" value="save changes" />
                        <br/>
                        <br/>
                        #{/form}
                        <script language="javascript">
                            $(document).ready(function(){
                                javascript: disable();
                            })
                        </script>
